package com.situ.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.connector.Request;

import com.situ.web.entity.User;
import com.situ.web.service.IUserService;
import com.situ.web.service.impl.UserServiceImpl;

public class Login1Servlet extends HttpServlet {
	private IUserService userService = new UserServiceImpl();
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		String name = req.getParameter("name");
		String password = req.getParameter("password");
		User user = userService.loginUser(name,password);
		HttpSession session = req.getSession();
		session.setAttribute("user", user);
		if (user != null) {
			resp.sendRedirect(req.getContextPath() + "/pageList");
		} else {
			resp.sendRedirect(req.getContextPath() + "/fail.html");
		}
	}

}
